package com.example.springboottx.mapper;

import com.example.springboottx.bean.Book;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface BookMapper {

    @Select("select * from book")
    @Results(id = "book",
            value = {
                    @Result(property = "id", column = "id", id = true),
                    @Result(property = "name", column = "book_name"),
                    @Result(property = "publishDate", column = "publish_date"),
//                    @Result(property = "path",column = "path"),
                    @Result(property = "publisher", column = "publisherId",
                            one = @One(select = "com.example.springboottx.mapper.PublisherMapper.findPublisherById",
                                    fetchType = FetchType.EAGER))
            })
    List<Book> findAllBooks();


    @Select("select * from book where id = #{id}")

    @Options(useCache = true)
    @ResultMap("book")
    Book findBookById(Integer id);

}
